home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
tcqbsnip.zip
/
SUBVARS.BAS
< prev
next >
Wrap
BASIC Source File
|
1997-06-20
|
2KB
|
58 lines
' SUBVARS.BAS
' by Tika Carr
'
' Donated to the public domain
' No warranties or guarantees are expressed or implied.
'
' Purpose: A demonstration of local and global variables between subroutines
DECLARE SUB Test ()
DECLARE SUB Test2 ()
DIM SHARED GlobalVar$ 'This is a global variable, you can use it in
'any SUB or FUNCTION and it won't lose its
'value.
LocalVar$ = "World" 'This is a local variable. This will not hold
'its value in any SUB or FUNCTION.
GlobalVar$ = "Hello" 'We can give a global variable a value
'anytime we want, even in a SUB or FUNCTION and
'it will stay that way until we change it
'again.
PRINT "Here are the variables before we go to a SUB: "
PRINT "GlobalVar$ ="; GlobalVar$
PRINT "LocalVar$ ="; LocalVar$
PRINT
PRINT "Here we will now go to the SUB to print them out:"
CALL Test
PRINT
PRINT "Here they are again, after the sub: "
PRINT "GlobalVar$ ="; GlobalVar$
PRINT "LocalVar$ ="; LocalVar$
PRINT
PRINT "Now, we will change them in another sub and print them out: "
CALL Test2
PRINT
PRINT "Here we are back in the main program again: "
PRINT "GlobalVar$ ="; GlobalVar$ 'This one held the new value
PRINT "LocalVar$ ="; LocalVar$ 'This one didn't hold the new
'value.
PRINT : PRINT "All Done!"
END
SUB Test
PRINT "GlobalVar$ ="; GlobalVar$ 'This one will hold its value
PRINT "LocalVar$ ="; LocalVar$ 'This one won't print anything
END SUB
SUB Test2
GlobalVar$ = "Another"
LocalVar$ = "String"
PRINT "GlobalVar$ ="; GlobalVar$ 'This one is now changed
PRINT "LocalVar$ ="; LocalVar$ 'So is this, but won't print in
'main program because its local to
'the SUB.
END SUB